package com.eleme.address.controller;

import com.eleme.address.dto.AddressAddDTO;
import com.eleme.address.dto.AddressUpdateDTO;
import com.eleme.address.service.AddressService;
import com.eleme.address.vo.AddressVO;
import com.eleme.address.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/DeliveryAddressController")
public class AddressController {
    @Autowired
    private AddressService addressService;

    @PostMapping("/add")
    public Result<String> addAddress(@Validated @RequestBody AddressAddDTO dto) {
        return Result.success(addressService.addAddress(dto));
    }

    @PostMapping("/update")
    public Result<String> updateAddress(@Validated @RequestBody AddressUpdateDTO dto) {
        return Result.success(addressService.updateAddress(dto));
    }

    @DeleteMapping("/remove/{addressId}")
    public Result<String> removeAddress(@PathVariable String addressId) {
        return Result.success(addressService.removeAddress(addressId));
    }

    @PostMapping("/default/{userId}/{addressId}")
    public Result<String> setDefault(@PathVariable String userId, @PathVariable String addressId) {
        return Result.success(addressService.setDefault(userId, addressId));
    }

    @GetMapping("/listDeliveryAddressByUserId/{userId}")
    public Result<List<AddressVO>> listDeliveryAddressByUserId(@PathVariable("userId") String userId) {
        return Result.success(addressService.listByUser(userId));
    }

    @GetMapping("/getDeliveryAddressById/{daId}")
    public Result<AddressVO> getDeliveryAddressById(@PathVariable("daId") Integer daId) {
        return Result.success(addressService.getById(daId.toString()));
    }

    @PostMapping("/saveDeliveryAddress/{contactName}/{contactSex}/{contactTel}/{address}/{userId}")
    public Result<Integer> saveDeliveryAddress(@PathVariable("contactName") String contactName, @PathVariable("contactSex") Integer contactSex, @PathVariable("contactTel") String contactTel, @PathVariable("address") String address, @PathVariable("userId") String userId) {
        // ... 保持原有业务逻辑
        return null; // Placeholder return, actual implementation needed
    }

    @PutMapping("/updateDeliveryAddress/{daId}/{contactName}/{contactSex}/{contactTel}/{address}")
    public Result<Integer> updateDeliveryAddress(@PathVariable("daId") Integer daId, @PathVariable("contactName") String contactName, @PathVariable("contactSex") Integer contactSex, @PathVariable("contactTel") String contactTel, @PathVariable("address") String address) {
        // ... 保持原有业务逻辑
        return null; // Placeholder return, actual implementation needed
    }
} 